package com.atguigu.gmall.search.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.search.bean.Goods;
import com.atguigu.gmall.search.service.SearchService;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/inner/rpc/search")
public class SearchController {
    @Autowired
    SearchService searchService;


    /**
     * 商品上架
     *
     * @param goods
     * @return
     */
    @PostMapping("up/goods")
    public Result up(@RequestBody Goods goods) {
        searchService.up(goods);
        return Result.ok();
    }

    /**
     * 商品下架
     *
     * @param skuId
     * @return
     */
    @GetMapping("/down/goods/{skuId}")
    public Result down(@PathVariable("skuId") Long skuId) {

        searchService.down(skuId);
        return Result.ok();
    }


    /**
     * 根据索引查询goods
     * @param param
     * @return
     */
    @PostMapping("/searchgoods")
    public Result<SearchRespVo> search(@RequestBody SearchParamVo param) {
        SearchRespVo searchRespVo = searchService.search(param);
        return Result.ok(searchRespVo);
    }

    /**
     * 增加热度分
     * @param skuId
     * @param score
     */
    @GetMapping("/hotscore/{skuId}/{score}")
    public  void updateHotScore(@PathVariable Long skuId,@PathVariable Long score){
        searchService.updateHotScore(skuId,score);
    }


}
